home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#23 (Aug 87)
/
MacHac source
/
validSrc.c
Wrap
Text File
|
1987-06-25
|
1KB
|
33 lines
/* Lightspeed C 2.01 source, based on the ValidPointer(), and Validhandle() */
/* routines in the Programmers Extender Vol 1 by Invention Software Inc. */
Boolean ValidPointer(P)
Ptr P;
{
if ((P == NULL) || ((long)P & 1L)) /* if pointer is NULL or odd */
return(FALSE); /* then pointer is definitely bad! */
/* In my opinion test for null should be ommitted, indexing into an array */
/* of characters (bytes) could result in a valid pointer to an odd address */
/* another test which should be added here is a check to see that the */
/* pointer is not above the tom of RAM, but MemTop() does not return the */
/* correct value when running under switcher or servant. */
else
return(TRUE); /* else pointer is potentially valid*/
}
Boolean ValidHandle(H)
Handle H;
{
Ptr P;
if (ValidPointer((Ptr)H)) { /* the handle dereferenced is OK */
P = (Ptr)((long)(*H) & 0x00FFFFFF); /* mask off the master pointer status bits */
if (ValidPointer((Ptr)P)) /* the pointer pointed to is OK */
return(TRUE); /* then Handle is potentially valid */
}
return(FALSE); /* Handle doesn't point to a pointer */
}